package com.bjor.models;

import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;


public class DrinkingPlan {
	
	private XYMultipleSeriesDataset dataset;
	private int minutesDuration;
	private Gender gender;
	private float weight, drinkAlcPerc;
	private int age, numberOfDrinks;
	private final double timeUnit = 0.5; // minutes

	public DrinkingPlan (int minutesDuration, Gender gender, float weight, int age, int numberOfDrinks, float drinkAlcPerc)
	{
		this.minutesDuration = minutesDuration;
		this.gender = gender;
		this.weight = weight;
		this.age = age;
		this.numberOfDrinks = numberOfDrinks;
		this.drinkAlcPerc = drinkAlcPerc;
	}
	
	public XYMultipleSeriesDataset getDataSet()
	{
		double totalAlchohol = numberOfDrinks * drinkAlcPerc * 500 * 1;
		double numberOfStdDrinks = totalAlchohol / 10;
		double stdDrinksPerTimeUnit = numberOfStdDrinks * timeUnit / minutesDuration;
		
	    dataset = new XYMultipleSeriesDataset();
	    XYSeries bacSeries = new XYSeries("BAC per time");
	    XYSeries drinkSeries = new XYSeries("Open drink");
	    
	    int timeUnitsBetweenDrinks = (int)(minutesDuration / (double)(numberOfDrinks * timeUnit));
	    
	    for(int i = 0; i < minutesDuration / timeUnit; i++)
	    {
	    	double x = i * timeUnit / 60;
	    	double bac = 0.806 * stdDrinksPerTimeUnit * i * 1.2 / (gender.BW * weight) - (gender.MR * i * timeUnit / 60);
	    	bacSeries.add( x, bac );
	    	
	    	if ( i % timeUnitsBetweenDrinks == 0 )
	    		drinkSeries.add(x, bac);
	    }
	    dataset.addSeries(bacSeries);
	    dataset.addSeries(drinkSeries);
	    
	    return dataset;
	}
//	public void UpdatePlan(Date to)

}
